setClass("VTestRunner",
		representation("VIRTUAL",
				.setList="list",	#bootstraper constructor checks it
				.compList="list",	#Bframework constructor checks it
				.bootstraperPrototype="VBootstrapedSet", #prototype to make new Sets in runTest
				.finalResultComp="VBFrameworkFinalResult",
				.scoreObj="VScore", #use to initialize BFramework
				#.bFramObj="BootstrapFramework",	#initialize in runTest
				.resultsDirectory="character",
				.description="character"
				),
		prototype=prototype(
				.description="Virtual Test Runner Class"
		),
		validity=function(.Object){
			#check setList
			classesPresent <-ifelse(is(.Object@.scoreObj,"ExternalClusterScore"), TRUE,FALSE)
			for(i in 1:length(.Object@.setList)){
				if( is.null(.Object@.setList[[i]]$X ) ){
					stop("One of sets does not contain X slot")
				}
				if(classesPresent && is.null(.Object@.setList[[i]]$Y)){
					stop("One of sets does not contain Y slot")
				}
				if(is.null( .Object@.setList[[i]]$Name ) ){
					stop("One of sets does not contain Name slot")
				}
			}
			
			
		}
)
#generics
setGeneric("runTest",function(.Object,...){standardGeneric("runTest")})

#initialization method

setMethod("initialize",
		signature="VTestRunner",
		definition=function(.Object,setList, compList, bootstraperPrototype, finalResultComp,scoreObj,
				resultsDirectory,...){
			
			.Object@.setList <-setList
			.Object@.compList <-compList
			.Object@.bootstraperPrototype <-bootstraperPrototype
			.Object@.finalResultComp <-finalResultComp
			.Object@.scoreObj <-scoreObj
			.Object@.resultsDirectory <-resultsDirectory
			
			validObject(.Object)
			
			if(! dir.create(.Object@.resultsDirectory) ){
				#TODO uncomment it in final version
				#stop("Directory ",.Object@.resultsDirectory,"already exists")
			}
			else{
				.Object@.resultsDirectory <- normalizePath(.Object@.resultsDirectory)
			}
			
			return(.Object)
		})

